package jjn.round1;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author Jjn
 * @since 2023/9/3 21:41
 */
public class LeetCode128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int longest = 0;
        for (int num : set) {
            if (!set.contains(num - 1)) {
                int start = num;
                int current = 1;
                while (set.contains(start + 1)) {
                    start++;
                    current++;
                }
                longest = Math.max(longest, current);
            }
        }
        return longest;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = scanner.nextInt();
            }
            int longestConsecutive = new LeetCode128().longestConsecutive(nums);
            System.out.println(longestConsecutive);
        }
    }
}
